"use strict";
this.JSONConfig = function () {};

this.JSONConfig.prototype = (function () {
    var init, thread, configuration, getExternalConfigurationLoader, trim;

    init = function (webLayout) {
        var node;
        node = webLayout.contentElement.firstChild;
        while (node !== null) {
            if (node.nodeType === 8) {
                if (node.nodeValue.substr(0, 30) ===
                        'WebLayout2-JSON configuration:') {
                    configuration = webLayout.json(node.nodeValue.
                            substring(30));
                    webLayout.moduleEvent('configurationLoaded',
                            configuration);
                    return;
                } else if (node.nodeValue.substr(0, 39) ===
                        'WebLayout2-JSON external configuration:') {
                    webLayout.ajaxLib.json(trim(node.nodeValue.substring(39)),
                            '', getExternalConfigurationLoader(webLayout));
                    return;
                }
            }
            node = node.nextSibling;
        }
    };

    trim = function (string) {
        return string.replace(/^\s*/, '').replace(/\s*$/, '');
    };

    thread = function (webLayout) {};

    getExternalConfigurationLoader = function (webLayout) {
        return function (response, status, xmlHttpRequest) {
            if (status === 200) {
                webLayout.moduleEvent('configurationLoaded', response);
            }
        };
    };

    return {
        NAME: 'JSONConfig',
        init: init,
        thread: thread
    };
}());